using System;
using System.Collections.Generic;
using System.Text;

namespace GoogleNet
{
    /// <summary>
    /// A Document is a container for features and styles. 
    /// This element is required if your KML file uses shared styles. 
    /// It is recommended that all Styles be defined in a Document, each with 
    /// an id, and then later referenced by a styleUrl for a given Feature or StyleMap.
    /// </summary>
    public class KmlDocument : KmlFeature, IKmlElement, IKmlContainer
    {
        private string tagName = "Document";

        #region IKmlElement Members

        /// <summary>
        /// Name of the KML tag for this specific element.
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        public override string TagName
        {
            get { return tagName; }
        }

        #endregion

        #region Features
        List<IKmlFeature> features = new List<IKmlFeature>();

        /// <summary>
        /// Gets or sets the features.
        /// </summary>
        /// <value>The features.</value>
        public List<IKmlFeature> Features
        {
            get { return features; }
            set { features = value; }
        } 
        #endregion

        #region IKmlGenerator Members

        /// <summary>
        /// Generates the KML for this element including its child elements.
        /// </summary>
        /// <param name="writer">The XML writer that will be used to generate the KML.</param>
        void IKmlGenerator.GenerateKml(System.Xml.XmlTextWriter writer)
        {
            writer.WriteStartElement(tagName);
            base.GenerateKml(writer);

            if (features.Count > 0)
            {
                foreach (IKmlFeature currentFeature in features)
                {
                    currentFeature.GenerateKml(writer);
                }
            }
            writer.WriteFullEndElement();
        }

        #endregion
    }
}
